<template>
  <div class="bgc-default pad-20">
    <div class="bg-color-white pad-20">
      <div class="tabs-box mar-t--10">
        <el-tabs v-model="tabActive" @tab-click="doChangeTab">
          <el-tab-pane :label="'发货单(' + sendTotal + ')'" name="send"> </el-tab-pane>
          <el-tab-pane :label="'包裹单(' + pacakgeTotal + ')'" name="package"> </el-tab-pane>
        </el-tabs>
      </div>
      <!-- 发货单 -->
      <order-send v-on:resetSendCount="resetSendCount" v-if="tabActive == 'send'"></order-send>
      <!-- 包裹单 -->
      <order-package v-if="tabActive == 'package'"></order-package>
    </div>
  </div>
</template>


<script>
  import { statOrderPackage } from '@/api/order/orderPackage'
  import { statSend } from '@/api/order/projectSend'
  import orderSend from './order-send'
  import orderPackage from './order-package'

  export default {
    components: {
      orderSend, orderPackage
    },
    data() {
      return {
        tabActive: 'send',
        sendTotal: 0,
        pacakgeTotal: 0
      }
    },
    created() {
      this.initSendCount()
      this.initPackageCount()
    },
    methods: {
      // tab切换事件
      doChangeTab() {
        switch (this.tabActive) {
          case 'send':
            this.initSendCount()
            break
          case 'package':
            this.initPackageCount()
            break
          default:
        }
      },
      // 统计发货单
      initSendCount() {
        const sendForm = {
          enterpriseId: this.getEnterpriseId(),
          supplierId: this.getSupplierId(),
          warehouseId: this.getWarehouseId()
        }
        if (!this.getWarehouseId() && !this.getSupplierId()) {
          // 只查企业总部发货单
          sendForm.source = 10
        }
        statSend(sendForm).then(response => {
          if (response.isError) return
          this.sendTotal = response.data['total']
        })
      },
      // 统计包裹单
      initPackageCount() {
        const packageForm = {
          enterpriseId: this.getEnterpriseId(),
          supplierId: this.getSupplierId(),
          warehouseId: this.getWarehouseId()
        }
        statOrderPackage(packageForm).then(response => {
          if (response.isError) return
          this.pacakgeTotal = response.data[90]
        })
      },
      // 重新统计发货单事件
      resetSendCount() {
        this.initSendCount()
      }
    }
  }
</script>

<style lang="less" scoped>

</style>